package com.dragandjuric.lse.boncote.service;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.dragandjuric.lse.boncote.Person;

public class PersonsBean implements Persons {

	private Map<String, Person> persons;
	
	public PersonsBean(Map<String, Person> persons) {
		super();
		this.persons = persons;
	}
	
	public PersonsBean() {
		this(new HashMap<String, Person>());
	}

	public Collection<Person> retrieve() {
		return persons.values();
	}
	
	public Person retrieve(String lastName) {
		return persons.get(lastName);
	}

	public Person save(Person person) {
		assert person != null;
		assert person.getLastName() != null;
		assert person.getLastName().length() > 1;
		return persons.put(person.getLastName(), person);
	}

}
